package com.ming.demo.web.impl.admin;

import com.github.pagehelper.PageHelper;
import com.ming.demo.bean.Result;
import com.ming.demo.mapper.InfoPeopleMapper;
import com.ming.demo.model.InfoPeople;
import com.ming.demo.web.admin.AdminInfoController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/info")
public class AdminInfoControllerImpl implements AdminInfoController {
    @Autowired
    private InfoPeopleMapper infoPeopleMapper;

    @Autowired
    private MongoTemplate mongoTemplate;

    @RequestMapping("/list")
    @Override
    public Result<List<InfoPeople>> listInfoPeople(int pageNO, int pageSize) {
        Query query = Query.query(Criteria.where("_class").is("com.ming.demo.model.InfoPeople")).skip((pageNO - 1) * pageSize).limit(pageNO * pageSize);
        List<InfoPeople> infoPeopleList =  mongoTemplate.find(query, InfoPeople.class);

/*
        PageHelper.startPage(pageNO,pageSize);
        List<InfoPeople> infoPeopleList = infoPeopleMapper.findAllPeople();
        */
        Result result = new Result();
        result.setCode("200");
        result.setData(infoPeopleList);
        return result;
    }
}
